{extend name="platform/base" /}
{block name="resources"/}
<script src="ADMIN_JS/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<style  type="text/css">
.set-style{
	width:100%;
}
.set-style dl{
	width:100%;
	font-size: 0;
	/* line-height: 20px; */
	clear: both;
	padding: 0;
	margin: 0;
	border-bottom: dotted 1px #E6E6E6;
	overflow: hidden;
}
.set-style dl dt{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	text-align: right;
	display: inline-block;
	width: 19%;
	padding: 10px 1% 10px 0;
	margin: 0;
	font-weight:normal;
}
.set-style dl dd{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	display: inline-block;
	width: 78%;
	padding: 10px 0 10px 0;
}
.set-style dl dd input[type="text"]{
	font: 12px/20px Arial;
	color: #777;
	background-color: #FFF;
	vertical-align: top;
	display: inline-block;
	height:24px;
	line-height:24px;
	padding: 4px;
	border: 1px solid #CCC;
	outline: 0 none;
	width: 400px;
	margin:0;
}
.set-style dl dd input[type="text"].w70{
	width:70px;
}
.set-style dl dd textarea{
    font: 12px/20px Arial;
    color: #777;
    background-color: #FFF;
    vertical-align: top;
    display: inline-block;
    height: 60px;
    padding: 4px;
    border: solid 1px #CCC;
    outline: 0 none;
	width: 400px;
	margin:0;
}
.hint{
    font-size: 12px;
    line-height: 16px;
    color: #BBB;
    margin-top: 10px;
}
.set-style dl dd p img{
	border: medium none;
	vertical-align: middle;
}
.class-Logo{
	background-color: #FFF;
	position: relative;
	z-index: 1;
}
.class-Logo p{
	width: 120px;
	height: 100px;
	line-height: 0;
	background-color: #FFF;
	text-align: center;
	vertical-align: middle;
	display: table-cell;
	*display: block;
	overflow: hidden;
	    margin: 0 0 10px;
		border: dashed 1px #E6E6E6;
}
.class-Logo p img{
	max-width: 120px;
	max-height: 100px;
	border: medium none;
	vertical-align: middle;
	margin-top: expression(60-this.height/2);
	*margin-top: expression(30-this.height/2);
}

.set-style dl dd p{
	margin-bottom:0;
}

.table-div  table tr td{
	    border: 1px solid #e6e6e6;
    padding: 10px;
}
.goodlist-table tr td{
	    border: 1px solid #e6e6e6;
    padding: 10px;
}
.form-horizontal .control-group {
    margin-bottom: 0px;
}
.form-horizontal .controls {
    margin-left: 20px; 
}
.help-inline{
	    height: 30px;
    	line-height: 30px;
}
input[type="radio"]{
	margin-top:6px;
}
.controls table tr td input[type="radio"]{
	margin:0px;
}
</style>
 {/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt>名称:</dt>
		<dd>
			<input type="text" id="coupon_name" maxlength="10"value="{$coupon_type_info.coupon_name}" >
			<p class="hint">10个字以内</p>
		</dd>
	</dl>
	<dl>
		<dt>面额:</dt>
		<dd><input class="input-mini w70" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"value="{$coupon_type_info.money}" type="text" id="money"><span class="help-inline">元</span></dd>
	</dl>
	<dl>
		<dt>发放数量:</dt>
		<dd><input class="input-mini w70" onkeyup='this.value=this.value.replace(/\D/gi,"")' type="text" id="count"value="{$coupon_type_info.count}"><span class="help-inline">份</span></dd>
	</dl>
	<dl>
		<dt>每人最大领取数:<br/>(0无限制)</dt>
		<dd><input class="input-mini w70" onkeyup='this.value=this.value.replace(/\D/gi,"")' type="text" id="max_fetch"value="{$coupon_type_info.max_fetch}"><span class="help-inline">份</span></dd>				
	</dl>
	<dl>
		<dt>满多少元使用:</dt>
		<dd><input class="input-mini w70" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')" type="text" id="at_least"value="{$coupon_type_info.at_least}"><span class="help-inline">元</span></dd>
	</dl>
	<dl style="display:none;">
		<dt>领取人等级:</dt>
		<dd><input class="input-mini w70" onkeyup='this.value=this.value.replace(/\D/gi,"")' type="text" id="need_user_level"value="{$coupon_type_info.need_user_level}"><span class="help-inline">级</span></dd>
	</dl>
	<dl>
		<dt>有效时间:</dt>
		<dd>
			<input class="input-medium" type="text" id="start_time" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})"value="{$coupon_type_info.start_time}">
			<span class="mlr5">-</span> 
			<input class="input-medium" size="15"type="text" id="end_time" style="width:250px;"onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'{$coupon_type_info.end_time}'})"value="{$coupon_type_info.end_time}">
			<!-- <span class="help-inline">生效前买家可以领取但不能使用</span> -->
			<p class="hint">生效前买家可以领取但不能使用</p>
		</dd>
	</dl>
	{include file="platform/promotion/selectGoods" /}
	<button class="edit_button" onclick="updateCouponType();">提交</button>
</div>
<input type="hidden"id="coupon_type_id" value="{$coupon_type_info.coupon_type_id}"/>
{include file="platform/openDialog" /}
<script>
$(function(){
	if({$coupon_type_info}.range_type == 1){
		$("input[type=radio][name='range_type'][value=1]").attr("checked","checked");
		ShopRadio(1);
	}
	var goods_id_array = {$coupon_type_info}.goods_id_array;
	LoadingInfo(goods_id_array);
});
	//保存
	function updateCouponType() {
		var coupon_type_id = $("#coupon_type_id").val();
		var coupon_name = $("#coupon_name").val();
		var money = $("#money").val();
		var count = $("#count").val();
		var max_fetch = $("#max_fetch").val();
		var at_least = $("#at_least").val();
		var need_user_level = $("#need_user_level").val();
		var range_type = $("input[name='range_type']:checked").val();
		var start_time = $("#start_time").val();
		var end_time = $("#end_time").val();
		var obj = $(".select-two table input[type=checkbox][name='sub']");
		var goods_id_array = '';
		obj.each(function(i){
			goods_id_array += ','+obj.eq(i).val();
		});
		goods_id_array = goods_id_array.substring(1);
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/Promotion/updateCouponType')}",
			data : {
				'coupon_type_id' : coupon_type_id,
				'coupon_name' : coupon_name,
				'money' : money,
				'count' : count,
				'at_least' : at_least,
				'max_fetch' : max_fetch,
				'need_user_level' : need_user_level,
				'range_type' : range_type,
				'start_time' : start_time,
				'end_time' : end_time,
				'goods_list' : goods_id_array
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"], "{:__URL('PLATFORM_MAIN/Promotion/couponTypeList')}");
				}else{
					showMessage('error', data["message"]);
				}	
			}
		});
	}
</script>
{/block}